<template>
  <el-dialog :title="title" :visible.sync="open" width="80%" append-to-body :close-on-click-modal="false" v-dialogDrag>
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch"
             label-width="110px">
      <!--<el-form-item label="发货通知编号" prop="tongzhiNo">
          <el-input v-model="queryParams.tongzhiNo" placeholder="请输入发货通知编号"
                  clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>-->
      <el-form-item label="发货单号" prop="fahuoNo">
        <el-input v-model="queryParams.fahuoNo" placeholder="请输入发货单号"
                  clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="订单编号" prop="proNo">
        <el-input v-model="queryParams.proNo" placeholder="请输入订单编号"
                  clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="产品编号" prop="nos">
        <el-input v-model="queryParams.nos" placeholder="请输入产品编号"
                  clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="产品名称" prop="name">
        <el-input v-model="queryParams.name" placeholder="请输入产品名称"
                  clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="产品型号" prop="models">
        <el-input v-model="queryParams.models" placeholder="请输入产品型号"
                  clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <!--<el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
            <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
                    v-hasPermi="['develop:LvYifahuomingxi:add']">新增</el-button>
        </el-col>
        <el-col :span="1.5">
            <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single"
                    @click="handleUpdate" v-hasPermi="['develop:LvYifahuomingxi:edit']">修改</el-button>
        </el-col>
        <el-col :span="1.5">
            <el-popconfirm title="确认删除选择的数据项？" @confirm="handleDelete({})">
                <el-button slot="reference" type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple"
                           v-hasPermi="['develop:LvYifahuomingxi:remove']">删除</el-button>
            </el-popconfirm>
        </el-col>
        <el-col :span="1.5">
            <el-button type="warning" plain icon="el-icon-download" size="mini"
                    @click="handleExport" v-hasPermi="['develop:LvYifahuomingxi:export']">导出</el-button>
        </el-col>+
        <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>-->

    <el-table border v-loading="loading" :data="dataList" @selection-change="handleSelectionChange" ref="table"
              :max-height="tableMaxHeight">
      <el-table-column type="selection" width="55" align="center"/>
      <!-- <el-table-column label="发货通知编号" align="center" prop="tongzhiNo" show-overflow-tooltip/>-->
      <el-table-column label="订单编号" align="center" prop="proNo" show-overflow-tooltip/>
      <el-table-column label="发货单号" align="center" prop="fahuoNo" show-overflow-tooltip/>
      <el-table-column label="产品编号" align="center" prop="nos" show-overflow-tooltip/>
      <el-table-column label="产品名称" align="center" prop="name" show-overflow-tooltip/>
      <el-table-column label="产品型号" align="center" prop="models" show-overflow-tooltip/>
      <el-table-column label="单位" align="center" prop="danwei"/>
      <el-table-column label="产品单价" align="center" prop="danjian"/>
      <el-table-column label="发货状态" align="center" prop="status">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.yifahuo_status" :value="scope.row.status"/>
        </template>
      </el-table-column>
      <el-table-column label="发货日期" align="center" prop="fahuoDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.fahuoDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="交货日期" align="center" prop="jiaohuoDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.jiaohuoDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="发货数量" align="center" prop="shuliang"/>
      <el-table-column label="发货金额" align="center" prop="money"/>
      <el-table-column align="center" class-name="small-padding fixed-width" label="操作" width="80">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-search"
                     @click="choseGoodsDeatil(scope.row)">选用明细
          </el-button>
          <el-button @click="qualityTestingFahuo(scope.row)"  icon="el-icon-view"
                     size="mini" type="text">产品质检
          </el-button>
          <!--<el-button size="mini" type="text" icon="el-icon-edit" @click="choseGoodsFahuo(scope.row)">选用产品</el-button>
          <el-popconfirm :title="`确认删除 `+scope.row.name+` 数据项？`" @confirm="handleDelete(scope.row)"
                         style="margin-left: 10px;">
            <el-button icon="el-icon-delete" size="mini" slot="reference" type="text"
                       v-hasPermi="['develop:ProjectBaseInfo:remove']">删除
            </el-button>
          </el-popconfirm>-->
        </template>
      </el-table-column>
      <!--<el-table-column label="发货状态" align="center" prop="status"/>-->
      <!--<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
          <template slot-scope="scope">
              <el-button size="mini" type="text" icon="el-icon-edit"
                      @click="handleUpdate(scope.row)" v-hasPermi="['develop:LvYifahuomingxi:edit']">修改</el-button>
              <el-popconfirm :title="`确认删除当前数据项？`" @confirm="handleDelete(scope.row)"
                             style="margin-left: 10px;">
                  <el-button slot="reference" size="mini" type="text" icon="el-icon-delete"
                             v-hasPermi="['develop:LvYifahuomingxi:remove']">删除</el-button>
              </el-popconfirm>
          </template>
      </el-table-column>-->
    </el-table>

    <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum"
                :limit.sync="queryParams.pageSize" @pagination="getList"/>

    <lvYifahuomingxi-form ref="form" @ok="getList"></lvYifahuomingxi-form>
    <choseGoodsDeatil-form-list ref="choseGoodsDeatilFormList" @ok="getList"></choseGoodsDeatil-form-list>
    <factory-test-quality-fahuo-detail ref="qualityTestingFahuoDetail" @ok="getList"></factory-test-quality-fahuo-detail>

  </el-dialog>
</template>

<script>
import {deleteAction, getAction} from '@/api/manage'
import LvYifahuomingxiForm from '@/views/develop/lvYifahuomingxi/module/LvYifahuomingxiForm'
import ChoseGoodsDeatilFormList from '@/views/develop/goodsSaleMaterial/module/ChoseGoodsDeatilFormList'
import FactoryTestQualityFahuoDetail
  from "@/views/develop/factory/factoryTestQuality/FactoryTestQualityFahuoDetail.vue";

export default {
  dicts: ['yifahuo_status'],
  name: "FahuoDeatilFormList",
  components: {
    FactoryTestQualityFahuoDetail,
    LvYifahuomingxiForm,
    ChoseGoodsDeatilFormList,
  },
  data() {
    return {
      title: '发货记录',
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      open: false,
      // 总条数
      total: 0,
      // 发货单明细表格数据
      dataList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        tongzhiId: null,
        tongzhiNo: null,
        jiaohuoDate: null,
        caigouNo: null,
        gonghuoNo: null,
        proId: null,
        proNo: null,
        prodName: null,
        saleId: null,
        name: null,
        models: null,
        mingxi: null,
        nos: null,
        danwei: null,
        danjian: null,
        shuliang: null,
        money: null,
        status: null,
        fahuoId: null,
        fahuoNo: null,
        orderByColumn: "fahuoNo",
        isAsc: "desc"
      },
      url: {
        list: '/lvYifahuomingxi/lvYifahuomingxi/list',
        remove: '/lvYifahuomingxi/lvYifahuomingxi/',
        export: '/lvYifahuomingxi/lvYifahuomingxi/export',
      },
      tableMaxHeight: window.innerHeight - 320,
    };
  },
  created() {
    this.getList();
    window.addEventListener('resize', this.getTableHeight);
  },
  destroyed() {
    window.removeEventListener('resize', this.getTableHeight)
  },
  methods: {
    choseGoodsDeatil(row) {
      this.$refs.choseGoodsDeatilFormList.show(row, "2");
    },
    show(row) {
      this.queryParams.proId = row.id;
      this.open = true;
      this.getList();
    },
    /** 查询发货单明细列表 */
    getList() {
      this.loading = true;
      getAction(this.url.list, this.queryParams).then(response => {
        this.dataList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    getTableHeight() {
      this.tableHeight = window.innerHeight - 320
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.$refs.form.handleAdd();
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.$refs.form.handleUpdate(row);
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      deleteAction(this.url.remove, ids).then(response => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(this.url.export, {
        ...this.queryParams
      }, `lvYifahuomingxi_${new Date().getTime()}.xlsx`)
    },

    qualityTestingFahuo(row){
      this.$refs.qualityTestingFahuoDetail.showByFahuoDetail(row);
    },
  }
};
</script>
